
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;
using System.Collections;
using System.Reflection;
using DesignPatternDefinitions;
namespace DotNetReverseEngineering
{
	/// <summary>
	/// Implements IMethod
	/// </summary>
	internal class RevEnggMethodInfo : IMethod
	{
		MethodInfo method;
		ArrayList parameters = new ArrayList();
		Hashtable metainfo;
		internal RevEnggMethodInfo(MethodInfo mthd)
		{
			this.method=mthd;
			this.metainfo=new Hashtable();
			this.InitParameters();
			this.InitMetaInfo();
		}
		
		private void InitParameters()
		{
			ParameterInfo [] paramArray = this.method.GetParameters();
				foreach (ParameterInfo pinfo in paramArray)
				{
					IParameter param = new RevEnggParameterInfo(pinfo);
					this.parameters.Add(param);
					
				}
		}
		
		private void InitMetaInfo()
		{
			string minfo="";
			if( this.method.IsAssembly ) minfo+="internal";
			if(this.method.IsConstructor) minfo+=" "+"ctor";
			if(this.method.IsFinal) minfo+=" "+"final";
			if(this.method.IsStatic) minfo+=" "+"static";
			if(this.method.IsVirtual) minfo+=" "+"virtual";
			
			this.metainfo.Add(RevEnggClassInfo.csharp,minfo);
		}

		
		#region IMethod Members

		public string MethodReturnType
		{
			get
			{
				return this.method.ReturnType.Name;
			}
			set
			{
				// Not Required
			}
		}

		public DesignPatternDefinitions.MethodType MethodType
		{
			get
			{
				if( this.method.IsAbstract )
					return DesignPatternDefinitions.MethodType.Abstract;
				return DesignPatternDefinitions.MethodType.Concrete;
			}
			set
			{
				// Not Required.
			}
		}

		public string MethodSummary
		{
			get
			{
				return string.Empty;
			}
			set
			{
				// Not Required.
			}
		}

		public Hashtable GetAllMetaInfo()
		{
			return this.metainfo;
		}

		public string MethodVisibility
		{
			get
			{
				if(this.method.IsPrivate)
					return DesignPatternDefinitions.AccessModifiers.Private.ToString().ToLower();
				if(this.method.IsPublic)
					return DesignPatternDefinitions.AccessModifiers.Public.ToString().ToLower();
				return DesignPatternDefinitions.AccessModifiers.Protected.ToString().ToLower();
			}
			set
			{
				// Not Required.
			}
		}

		public void SetMetaInfo(string metainfo)
		{
			// TODO:  Add RevEnggMethodInfo.SetMetaInfo implementation
		}

		public string MethodName
		{
			get
			{
				return this.method.Name;
			}
			set
			{
				// Not Required.
			}
		}

		public string GetMetaInfo(string language)
		{
			// TODO:  Add RevEnggMethodInfo.GetMetaInfo implementation
			return null;
		}

		public string UMLRepresentation
		{
			get
			{
				// TODO:  Add RevEnggMethodInfo.UMLRepresentation getter implementation
				return null;
			}
		}

		public ArrayList Parameters
		{
			get
			{
				return this.parameters;	
			}
			set
			{
				
			}
		}

		public object MethodUID
		{
			get
			{
				return null;
			}
		}
		

		#endregion
	}
}
